﻿<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${info.mapperPackage}.${info.mapperName}">
    <resultMap id="BaseResultMap" type="${info.entityPackage}.${info.entityName}">
    <#list tableList as table>
    <#if table.primary>
        <id column="${table.colname}" jdbcType="${table.jdbcType}" property="${table.lowerColname}" />
    <#else>
        <result column="${table.colname}" jdbcType="${table.jdbcType}" property="${table.lowerColname}" />
    </#if>
    </#list>
    </resultMap>
    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${r'${criterion.condition}'}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${r'${criterion.condition}'} ${r'#{criterion.value}'}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${r'${criterion.condition}'} ${r'#{criterion.value}'} and ${r'#{criterion.secondValue}'}
                                </when>
                                <when test="criterion.listValue">
                                    and ${r'${criterion.condition}'}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                                    ${r'#{listItem}'}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${r'${criterion.condition}'}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${r'${criterion.condition}'} ${r'#{criterion.value}'}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${r'${criterion.condition}'} ${r'#{criterion.value}'} and ${r'#{criterion.secondValue}'}
                                </when>
                                <when test="criterion.listValue">
                                    and ${r'${criterion.condition}'}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                                    ${r'#{listItem}'}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
    <#list tableList as table>${table.colname}<#if table_has_next>,</#if></#list>
    </sql>
    <select id="selectByExample" parameterType="${info.entityPackage}.${info.criteriaName}" resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List" />
        from ${tableName}
        <if test="_parameter != null">
            <include refid="Example_Where_Clause" />
        </if>
        <if test="orderByClause != null">
            order by ${r'${orderByClause}'}
        </if>
    </select>
    <#if tableKey?exists>
    <select id="selectByPrimaryKey" parameterType="java.lang.${tableKey.javaType}" resultMap="BaseResultMap">
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <include refid="Base_Column_List" />
        from ${tableName}
        where ${tableKey.colname} = ${r'#{'}${tableKey.lowerColname},jdbcType=${tableKey.jdbcType}${r'}'}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.${tableKey.javaType}">
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from ${tableName}
        where ${tableKey.colname} = ${r'#{'}${tableKey.lowerColname},jdbcType=${tableKey.jdbcType}${r'}'}
    </delete>
    </#if>
    <delete id="deleteByExample" parameterType="${info.entityPackage}.${info.criteriaName}">
        delete from ${tableName}
        <if test="_parameter != null">
            <include refid="Example_Where_Clause" />
        </if>
    </delete>
    <insert id="insert" parameterType="${info.entityPackage}.${info.entityName}">
        <#if needSelectKey?? && needSelectKey>
        <selectKey keyProperty="${tableKey.lowerColname}" order="AFTER" resultType="java.lang.${tableKey.javaType}">
            <#if tableKey.javaType == 'String'>select replace(uuid(),'-','')
            <#else>SELECT LAST_INSERT_ID()
            </#if>
        </selectKey>
        </#if>
        insert into ${tableName} (<#list tableList as table>${table.colname}<#if table_has_next>,</#if></#list>)
        values (<#list tableList as table>${r'#{'}${table.lowerColname},jdbcType=${table.jdbcType}${r'}'}<#if table_has_next>,</#if></#list>)
    </insert>
    <insert id="insertSelective" parameterType="${info.entityPackage}.${info.entityName}">
        <#if needSelectKey?? && needSelectKey>
        <selectKey keyProperty="${tableKey.lowerColname}" order="AFTER" resultType="java.lang.${tableKey.javaType}">
            <#if tableKey.javaType == 'String'>select replace(uuid(),'-','')
            <#else>SELECT LAST_INSERT_ID()
            </#if>
        </selectKey>
        </#if>
        insert into ${tableName}
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="${tableKey.lowerColname} != null">
            ${tableKey.colname},
            </if>
            <#list tableList as table>
            <#if !table.primary>
            <if test="${table.lowerColname} != null">
                ${table.colname},
            </if>
            </#if>
            </#list>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="${tableKey.lowerColname} != null">
            ${r'#{'}${tableKey.lowerColname},jdbcType=${tableKey.jdbcType}${r'}'},
            </if>
            <#list tableList as table>
            <#if !table.primary>
            <if test="${table.lowerColname} != null">
            ${r'#{'}${table.lowerColname},jdbcType=${table.jdbcType}${r'}'},
            </if>
             </#if>
            </#list>
        </trim>
    </insert>
    <select id="countByExample" parameterType="${info.entityPackage}.${info.criteriaName}" resultType="java.lang.Integer">
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select count(*) from ${tableName}
        <if test="_parameter != null">
            <include refid="Example_Where_Clause" />
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update ${tableName}
        <set>
            <#list tableList as table>
            <if test="record.${table.lowerColname} != null">
            ${table.colname} = ${r'#{'}record.${table.lowerColname},jdbcType=${table.jdbcType}${r'}'},
            </if>
            </#list>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause" />
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update ${tableName}
        set
        <#list tableList as table>
        ${table.colname} = ${r'#{'}record.${table.lowerColname},jdbcType=${table.jdbcType}${r'}'}<#if table_has_next>,</#if>
        </#list>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause" />
        </if>
    </update>
<#if tableKey?exists>
    <update id="updateByPrimaryKeySelective" parameterType="${info.entityPackage}.${info.entityName}">
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update ${tableName}
        <set>
        <#list tableList as table>
        <#if !table.primary>
                <if test="${table.lowerColname} != null">
                ${table.colname} = ${r'#{'}${table.lowerColname},jdbcType=${table.jdbcType}${r'}'},
                </if>
        </#if>
        </#list>
        </set>
        where ${tableKey.colname} = ${r'#{'}${tableKey.lowerColname},jdbcType=${tableKey.jdbcType}${r'}'}
    </update>
    <update id="updateByPrimaryKey" parameterType="${info.entityPackage}.${info.entityName}">
        <!--
          WARNING - @mbggenerated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update ${tableName}
        set
    <#list tableList as table>
        <#if !table.primary>
        ${table.colname} = ${r'#{'}${table.lowerColname},jdbcType=${table.jdbcType}${r'}'}<#if table_has_next>,</#if>
        </#if>
    </#list>
        where ${tableKey.colname} = ${r'#{'}${tableKey.lowerColname},jdbcType=${tableKey.jdbcType}${r'}'}
    </update>
</#if>
</mapper>